home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / imprisoned / code.lua next >
Encoding:
Text File  |  2005-07-16  |  15.5 KB  |  427 lines

  1.  
  2. -- -----------------------------------------------------------------
  3. -- Init
  4. -- -----------------------------------------------------------------
  5. local function prog_init()
  6.     initModels()
  7.     sound_playMusic("music/rybky03.ogg")
  8.     local pokus = getRestartCount()
  9.  
  10.  
  11.     -- -------------------------------------------------------------
  12.     local function prog_init_room()
  13.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  14.  
  15.         room.uvod = 0
  16.         room.sas = 0
  17.         room.kuk = 0
  18.         room.okoralech = 0
  19.         room.obarvach = 0
  20.         room.neprojedes = 0
  21.         room.mohlabys = 0
  22.  
  23.         return function()
  24.             if isReady(small) and isReady(big) and no_dialog() then
  25.                 if room.uvod == 0 then
  26.                     room.uvod = 1
  27.                     switch(random(1)){
  28.                         [0] = function()
  29.                             addm(20 + random(30), "ncp-m-tesno0")
  30.                         end,
  31.                         [1] = function()
  32.                             addm(20 + random(30), "ncp-m-tesno1")
  33.                         end,
  34.                     }
  35.                     if random(100) < 30 then
  36.                         addv(random(8), "ncp-v-dostala")
  37.                     end
  38.                 elseif look_at(small, sasanka) and dist(small, sasanka) < 3 and room.sas == 0 and random(100) < 20 then
  39.                     addv(random(5), "ncp-v-sasanka")
  40.                     room.sas = 1
  41.                 elseif look_at(small, konik) and konik.afaze == 3 and dist(small, konik) < 4 and room.kuk == 0 then
  42.                     addm(random(5), "ncp-m-nekoukej")
  43.                     room.kuk = 1
  44.                 elseif (koral1.dir ~= dir_no or koral2.dir ~= dir_no or koral3.dir ~= dir_no or koral0.dir ~= dir_no) and room.okoralech == 0 and random(100) < 2 then
  45.                     room.okoralech = 1
  46.                     if big.dir ~= dir_no then
  47.                         addv(0, "ncp-v-mekky")
  48.                     else
  49.                         switch(random(5)){
  50.                             [4] = function()
  51.                                 addm(0, "ncp-m-komari")
  52.                                 addv(random(3), "ncp-v-ceho")
  53.                                 addm(random(3), "ncp-m-koraly")
  54.                             end,
  55.                             default = function()
  56.                                 addm(0, "ncp-m-tvrdy")
  57.                             end,
  58.                         }
  59.                     end
  60.                 elseif big.X == 4 and big.Y == 29 and room.neprojedes == 0 and random(100) < 10 then
  61.                     addv(random(3), "ncp-v-neprojedu")
  62.                     room.neprojedes = 1
  63.                 elseif room.obarvach == 0 and random(10000) < 5 then
  64.                     room.obarvach = 1
  65.                     addm(random(10), "ncp-m-barvy")
  66.                 elseif valec.X == 3 and valec.Y == 34 and room.mohlabys == 0 then
  67.                     room.mohlabys = 1
  68.                     addv(random(3), "ncp-v-tak")
  69.                     if random(100) < 80 then
  70.                         addm(random(10), "ncp-m-muzes")
  71.                     end
  72.                 end
  73.             end
  74.         end
  75.     end
  76.  
  77.     -- -------------------------------------------------------------
  78.     local function prog_init_sasanka()
  79.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  80.  
  81.         sasanka.cinnost = 0
  82.         sasanka.noha = 0
  83.         sasanka.kvet = 1
  84.         sasanka.akcnost = 1
  85.  
  86.         return function()
  87.             if sasanka.cinnost ~= 5 and (dist(small, sasanka) < 3 or dist(big, sasanka) < 3) then
  88.                 sasanka.cinnost = 5
  89.                 sasanka.counts = random(10) + 15
  90.                 sasanka.akcnost = 1
  91.             end
  92.             if sasanka.cinnost == 0 then
  93.                 sasanka.cinnost = random(4) + 1
  94.                 sasanka.fazec = 0
  95.                 sasanka.akcnost = 2 + random(2)
  96.             end
  97.             if math.mod(game_getCycles(), sasanka.akcnost) == 0 then
  98.                 cinnost_table = {
  99.                     [1] = function()
  100.                         sasanka.noha = math.floor(sasanka.fazec / 4)
  101.                         if sasanka.cinnost == 1 then
  102.                             sasanka.kvet = math.mod(sasanka.fazec, 2) + 1
  103.                             sasanka.akcnost = 2
  104.                             if sasanka.kvet == 2 then
  105.                                 sasanka:talk("ncp-x-tup", VOLUME_FULL)
  106.                             end
  107.                         else
  108.                             sasanka.kvet = math.mod(sasanka.fazec, 2) * 2 + 1
  109.                             sasanka.akcnost = 3
  110.                         end
  111.                         sasanka.fazec = sasanka.fazec + 1
  112.                         if sasanka.fazec == 8 then
  113.                             if random(100) < 30 then
  114.                                 sasanka.cinnost = 0
  115.                             else
  116.                                 sasanka.fazec = 0
  117.                             end
  118.                         end
  119.                     end,
  120.                     [3] = function()
  121.                         switch(sasanka.fazec){
  122.                             [0] = function()
  123.                                 sasanka.counts = random(10) + 7
  124.                                 sasanka.fazec = sasanka.fazec + 1
  125.                                 sasanka.kvet = 1
  126.                             end,
  127.                             [1] = function()
  128.                                 sasanka.noha = 1 - sasanka.noha
  129.                                 sasanka.counts = sasanka.counts - 1
  130.                                 if sasanka.counts == 0 then
  131.                                     sasanka.fazec = sasanka.fazec + 1
  132.                                 end
  133.                             end,
  134.                             [2] = function()
  135.                                 if sasanka.cinnost == 3 then
  136.                                     sasanka.kvet = 0
  137.                                     sasanka.counts = random(8) + 5
  138.                                 else
  139.                                     sasanka.kvet = 3
  140.                                     sasanka.counts = random(6) + 3
  141.                                 end
  142.                                 sasanka.fazec = sasanka.fazec + 1
  143.                             end,
  144.                             [3] = function()
  145.                                 sasanka.counts = sasanka.counts - 1
  146.                                 if sasanka.counts == 0 then
  147.                                     if random(100) < 30 then
  148.                                         sasanka.cinnost = 0
  149.                                     else
  150.                                         sasanka.fazec = 0
  151.                                     end
  152.                                 end
  153.                             end,
  154.                         }
  155.                     end,
  156.                     [5] = function()
  157.                         sasanka.akcnost = 2
  158.                         sasanka.counts = sasanka.counts - 1
  159.                         switch(sasanka.counts){
  160.                             [0] = function()
  161.                                 sasanka.cinnost = 0
  162.                             end,
  163.                             [1] = function()
  164.                                 sasanka.kvet = 1
  165.                                 sasanka.noha = 1 - sasanka.noha
  166.                             end,
  167.                             default = function()
  168.                                 sasanka.kvet = 0
  169.                             end,
  170.                         }
  171.                     end,
  172.                 }
  173.  
  174.                 cinnost_table[2] = cinnost_table[1]
  175.                 cinnost_table[4] = cinnost_table[3]
  176.                 switch(sasanka.cinnost)(cinnost_table)
  177.             end
  178.             sasanka.afaze = sasanka.noha * 4 + sasanka.kvet
  179.             sasanka:updateAnim()
  180.         end
  181.     end
  182.  
  183.     -- -------------------------------------------------------------
  184.     local function prog_init_snek()
  185.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  186.  
  187.         snek.stav = 0
  188.  
  189.         return function()
  190.             switch(snek.stav){
  191.                 [0] = function()
  192.                     if snek.dir ~= dir_no then
  193.                         snek.stav = 1
  194.                     end
  195.                 end,
  196.                 [1] = function()
  197.                     snek.afaze = 3
  198.                     snek.stav = snek.stav + 1
  199.                 end,
  200.                 [2] = function()
  201.                     snek.afaze = 1
  202.                     snek.stav = snek.stav + 1
  203.                 end,
  204.                 [3] = function()
  205.                     snek.afaze = 2
  206.                     if snek.dir == dir_no then
  207.                         snek.stav = 4
  208.                         snek.count = 20
  209.                     end
  210.                 end,
  211.                 [4] = function()
  212.                     snek.count = snek.count - 1
  213.                     if snek.count == 0 then
  214.                         snek.stav = 5
  215.                         snek.count = 5
  216.                     end
  217.                     if snek.dir ~= dir_no then
  218.                         snek.stav = 2
  219.                     end
  220.                 end,
  221.                 [5] = function()
  222.                     snek.afaze = 1
  223.                     snek.count = snek.count - 1
  224.                     if snek.count == 0 then
  225.                         snek.afaze = 0
  226.                         snek.stav = 0
  227.                     end
  228.                     if snek.dir ~= dir_no then
  229.                         snek.stav = 1
  230.                     end
  231.                 end,
  232.             }
  233.             snek:updateAnim()
  234.         end
  235.     end
  236.  
  237.     -- -------------------------------------------------------------
  238.     local function prog_init_small()
  239.         local small_boring = 0
  240.         local small_smile = 4
  241.         local xicht = 0
  242.  
  243.         return function()
  244.             if small:getAction() == "rest" then
  245.                 small_boring = small_boring + 1
  246.             else
  247.                 small_boring = 0
  248.             end
  249.             if small_boring >= 15 and small_boring < 40 and look_at(small, konik) and ydist(small, konik) == 0 and xdist(small, konik) < 3 then
  250.                 if xicht ~= small_smile then
  251.                     xicht = small_smile
  252.                     konik.stav = 7
  253.                 end
  254.             else
  255.                 xicht = 0
  256.             end
  257.             if xicht ~= 0 then
  258.                 small:useSpecialAnim("head_all", xicht)
  259.             end
  260.         end
  261.     end
  262.  
  263.     -- -------------------------------------------------------------
  264.     local function prog_init_big()
  265.         local big_boring = 0
  266.         local xicht = 0
  267.         return function()
  268.             if big:getAction() == "rest" then
  269.                 big_boring = big_boring + 1
  270.             else
  271.                 big_boring = 0
  272.             end
  273.             if big_boring >= 15 and big_boring < 40 and look_at(big, konik) and ydist(big, konik) == 0 and xdist(big, konik) < 3 then
  274.                 if xicht ~= 6 then
  275.                     xicht = 6
  276.                     konik.stav = 7
  277.                 end
  278.             else
  279.                 xicht = 0
  280.             end
  281.             if xicht ~= 0 then
  282.                 big:useSpecialAnim("head_all", xicht)
  283.             end
  284.         end
  285.     end
  286.  
  287.     -- -------------------------------------------------------------
  288.     local function prog_init_konik()
  289.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  290.  
  291.         konik.stav = 0
  292.         konik.mrkani = 0
  293.  
  294.         return function()
  295.             if konik.stav ~= 2 and konik.dir == dir_down then
  296.                 konik:talk("ncp-x-ihaha", VOLUME_FULL)
  297.             end
  298.             if konik.dir == dir_down or elko.dir == dir_down then
  299.                 konik.stav = 2
  300.             elseif konik.stav == 2 then
  301.                 konik.stav = 0
  302.             end
  303.             switch(konik.stav){
  304.                 [0] = function()
  305.                     pom1 = 15
  306.                     if look_at(small, konik) and math.abs(xdist(small, konik)) <= 3 and math.abs(ydist(small, konik)) <= 1 then
  307.                         pom1 = 0
  308.                     end
  309.                     if look_at(big, konik) and math.abs(xdist(big, konik)) <= 3 and math.abs(ydist(big, konik)) <= 1 then
  310.                         pom1 = 0
  311.                     end
  312.                     if random(100) < pom1 then
  313.                         konik.stav = 1
  314.                         konik.mrkani = 0
  315.                     end
  316.                     konik.afaze = 0
  317.                 end,
  318.                 [2] = function()
  319.                     konik.afaze = 3
  320.                 end,
  321.                 [6] = function()
  322.                     konik.stav = 10
  323.                     konik.mrkani = 10
  324.                 end,
  325.                 [7] = function()
  326.                     konik.mrkani = 10
  327.                     konik.stav = 8
  328.                 end,
  329.                 [8] = function()
  330.                     konik.mrkani = konik.mrkani - 1
  331.                     if konik.mrkani == 0 then
  332.                         konik.stav = 3
  333.                     end
  334.                 end,
  335.                 [10] = function()
  336.                     if konik.mrkani > 0 then
  337.                         konik.mrkani = konik.mrkani - 1
  338.                     else
  339.                         konik.stav = 11
  340.                     end
  341.                 end,
  342.                 [11] = function()
  343.                     konik.afaze = 3
  344.                     konik.mrkani = random(10) + 10
  345.                     konik.stav = konik.stav + 1
  346.                 end,
  347.                 [12] = function()
  348.                     if konik.mrkani > 0 then
  349.                         konik.mrkani = konik.mrkani - 1
  350.                     else
  351.                         konik.afaze = 0
  352.                         konik.stav = 0
  353.                     end
  354.                 end,
  355.                 default = function()
  356.                     if isIn(konik.stav, {1, 3, 4, 5}) then
  357.                         switch(konik.mrkani){
  358.                             [0] = function()
  359.                                 konik.afaze = 2
  360.                             end,
  361.                             [1] = function()
  362.                                 konik.afaze = 1
  363.                                 konik:talk("ncp-x-tik", VOLUME_FULL)
  364.                             end,
  365.                             [2] = function()
  366.                                 konik.afaze = 2
  367.                             end,
  368.                             [3] = function()
  369.                                 konik.afaze = 0
  370.                                 konik.mrkani = -1
  371.                                 if konik.stav == 1 then
  372.                                     konik.stav = 0
  373.                                 else
  374.                                     konik.stav = konik.stav + 1
  375.                                 end
  376.                             end,
  377.                         }
  378.                         konik.mrkani = konik.mrkani + 1
  379.                     end
  380.                 end,
  381.             }
  382.             konik:updateAnim()
  383.         end
  384.     end
  385.  
  386.     -- --------------------
  387.     local update_table = {}
  388.     local subinit
  389.     subinit = prog_init_room()
  390.     if subinit then
  391.         table.insert(update_table, subinit)
  392.     end
  393.     subinit = prog_init_sasanka()
  394.     if subinit then
  395.         table.insert(update_table, subinit)
  396.     end
  397.     subinit = prog_init_snek()
  398.     if subinit then
  399.         table.insert(update_table, subinit)
  400.     end
  401.     subinit = prog_init_small()
  402.     if subinit then
  403.         table.insert(update_table, subinit)
  404.     end
  405.     subinit = prog_init_big()
  406.     if subinit then
  407.         table.insert(update_table, subinit)
  408.     end
  409.     subinit = prog_init_konik()
  410.     if subinit then
  411.         table.insert(update_table, subinit)
  412.     end
  413.     return update_table
  414. end
  415. local update_table = prog_init()
  416.  
  417.  
  418. -- -----------------------------------------------------------------
  419. -- Update
  420. -- -----------------------------------------------------------------
  421. function prog_update()
  422.     for key, subupdate in pairs(update_table) do
  423.         subupdate()
  424.     end
  425. end
  426.  
  427.